package com.yzfarm.biujoke.biujoke.mvp.model.http;

import android.util.Log;

import com.yzfarm.biujoke.biujoke.utils.JsoupUtil;
import com.yzfarm.biujoke.biujoke.utils.pojo.NewMeinvItem;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import static android.R.id.list;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;

/**
 * Created by hanhy on 2016/9/28.
 */

public class MeiNvApis {

    private ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3);

    public void getNewMeiNvs(final MeinvApiCallback<List<NewMeinvItem>> callback) {
        new Thread(){
            @Override
            public void run() {
                super.run();
                List<NewMeinvItem> list = JsoupUtil.getNewMeinvPic();
                callback.onSuccess(list);
                Log.d("Test","size = " + list.size());
            }
        }.start();



    }

    public void getOneMeiNvs(final String linkHref,final MeinvApiCallback<List<String>> callback){

        fixedThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                List<String> oneList = JsoupUtil.getOneMeinvPic(linkHref);
                callback.onSuccess(oneList);
            }
        });
    }


    String request(String url) throws IOException {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder().url(url).build();
        Response response = client.newCall(request).execute();
        if (response.isSuccessful()) {
            return response.body().string();
        } else {
            throw new IOException("Unexpected code " + response);
        }
    }

    public interface MeinvApiCallback<E>{
        void onSuccess(E list);
    }






}
